<template>
	<view class="white">
		<u-navbar :is-back="false" :border-bottom="false" :background="{ background: '#fff' }">
			<view class="slot-wrap flex align-center">
				<text class="cuIcon-back" @click="Back"></text>
				收藏
			</view>
		</u-navbar>
		<!-- #ifdef H5 -->
		<u-sticky index='1' :offset-top="0" :enable="enable">
		<!-- #endif -->
		<!-- #ifndef  H5 -->
		<u-sticky index='1' :offset-top="offsetTop" h5-nav-height="44" :enable="enable">
		<!-- #endif -->
			<view class="tabs">
				<u-tabs :list="list" bar-height="4" :is-scroll="false" :current="current" :bold="false" active-color="#FE7E00"
					@change="change"></u-tabs>
			</view>
		</u-sticky>
		
		<view class="main">
			<view class="flex">
				<image src="../../static/images/banren.png" mode="aspectFill" @click="routes('/pages/details/details')"></image>
				<view class="u-flex-1 flex flex-direction justify-between">
					<view class="">
						<view class="u-font-30 text-bold" @click="routes('/pages/details/details')">
							中华墨坊课程介绍
						</view>
						<view class="u-font-24">
							5万+人收藏
						</view>
						<view class="u-font-36 text-orange text-bold">
							免费
						</view>
					</view>
					<view class="text-right">
						<button class="cu-btn round line-orange">
							取消收藏
						</button>
					</view>
				</view>
			</view>
			<view class="flex">
				<image src="../../static/images/banren.png" mode="aspectFill" @click="routes('/pages/details/details')"></image>
				<view class="u-flex-1 flex flex-direction justify-between">
					<view class="">
						<view class="u-font-30 text-bold" @click="routes('/pages/details/details')">
							中华墨坊课程介绍
						</view>
						<view class="u-font-24">
							5万+人收藏
						</view>
						<view class="u-font-36 text-orange text-bold">
							免费
						</view>
					</view>
					<view class="text-right">
						<button class="cu-btn round line-orange">
							取消收藏
						</button>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				enable: true,
				offsetTop: 0,
				
				list: [{
					name: '知识课程'
				}, {
					name: '直播课程'
				}],
				current: 0,
			}
		},
		onLoad() {

		},
		onShow() {
			this.setOffestTop()
		},
		methods: {
			// 适配吸顶tab高度
			setOffestTop() {
				let systemInfo = uni.getSystemInfoSync()
				let topPx = systemInfo.statusBarHeight + 44 // 顶部状态栏+沉浸式自定义顶部导航
				this.offsetTop = topPx / (uni.upx2px(topPx) / topPx) // px转rpx
				console.log(this.offsetTop)
			},
			Back(){
				uni.navigateBack({
				});
			},
			change(index) {
				this.current = index;
			},
			routes(url) {
				if(url && url.length>0){
					console.log('+++++',url.indexOf('http'))
				    if(url.indexOf('http')===0){
						// #ifdef H5 
							location.href=url
						// #endif
						// #ifdef MP-WEIXIN
							 uni.navigateTo({ 
								 url:'/pages/web/web?url='+encodeURIComponent(url)
							 })
						// #endif
						// #ifdef APP-PLUS
						plus.runtime.openURL(url, function(res) {  
							console.log(res);  
						});
						// #endif
					}else if(url.indexOf('&switch')>-1){
						url =url.substring(0,url.indexOf('&switch'))
						console.log(3434,url)
				        uni.switchTab({
							url:url
						})
				    }else {
				        console.log("挑起",url)
				        uni.navigateTo({url})
				    }
				}
			}
		}
	}
</script>

<style lang="scss">
	.tabs {
		padding: 20rpx 0;
	}
	.main-box{
		.title{
			padding: 30rpx;
			.u-font-24{
				color: #666;
				margin-top: 0rpx;
			}
		}
	}
	.main{
		margin-top: 25rpx;
		>.flex{
			padding: 0rpx 30rpx 35rpx;
			background-color: #FFFFFF;
			image{
				width: 335rpx;
				height: 250rpx;
				border-radius: 6rpx;
				margin-right: 30rpx;
			}
			.u-font-30{
				color: #333;
				margin-right: 10rpx;
				overflow:hidden;
				text-overflow:ellipsis;
				display:-webkit-box;
				-webkit-box-orient:vertical;
				-webkit-line-clamp:2;
			}
			.u-font-28{
				color: #666;
				margin-top: 20rpx;
			}
			.u-font-36{
				margin-top: 20rpx;
			}
			.cu-btn{
				font-size: 24rpx;
			}
		}
	}
	
</style>
